<template>
  <div class="app-container">
    <div class="head">
      <div class="headinput">
        <i>项目名称:</i>
        <el-input
          placeholder="请输入项目名称"
          v-model="tempname.inspectionName"
          size="small"
          clearable
        >
        </el-input>

        <el-button
          type="primary"
          style="margin-left: 3px"
          plain
          icon="el-icon-search"
          size="small"
          class="select1"
          @click="dhipQuery"
          >查询</el-button
        >

        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="small"
          class="add"
          @click="handleAdd"
          >新增</el-button
        >
        <!-- </el-col>
                  </el-row> -->
      </div>
    </div>

    <!-- <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
         
        >修改</el-button>
      </el-col> -->
    <!-- <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
        
        >删除</el-button>
      </el-col> -->
    <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          
        >导出</el-button>
      </el-col> -->
    <!-- <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> -->

    <el-table class="el-table" :data="list">
      <!-- <el-table-column label="id" align="center" prop="patientId" />
      <el-table-column label="所属医院" align="center" prop="hospitalId" />
      <el-table-column label="患者姓名" align="center" prop="name" />
      <el-table-column label="微信" align="center" prop="openid" />
      <el-table-column label="患者电话" align="center" prop="mobile" />
      <el-table-column label="患者性别" align="center" prop="sex" />
      <el-table-column label="地址信息" align="center" prop="address" />
      <el-table-column label="过敏信息" align="center" prop="allergyInfo" /> -->
      <el-table-column label="ID" align="center" prop="insId" />
      <!-- <el-table-column label="添加用户id" align="center" prop="mid" />
      <el-table-column label="医院id" align="center" prop="hid" /> -->
      <el-table-column label="项目名称" align="center" prop="inspectionName" />
      <el-table-column label="项目类别" align="center" prop="classType" />
      <el-table-column label="项目单价" align="center" prop="unitPrice" />
      <el-table-column label="项目成本" align="center" prop="cost" />
      <el-table-column label="创建时间" align="center" prop="createTime" />
      <el-table-column label="修改时间" align="center" prop="updateTime" />
      <!-- <el-table-column label="单位" align="center" prop="unit" /> -->
      <!-- <el-table-column label="类别id" align="center" prop="classId" /> -->

      <!-- <el-table-column>
      <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          
          @click="handleUpdate(row)"
        
        >修改</el-button></el-table-column> -->

      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[8, 10, 20, 30, 40]"
      :page-size="100"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>

    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <!-- <el-form-item label="患者编号" prop="patientId">
          <el-input v-model="form.fileId" placeholder="请输入患者编号" />
        </el-form-item> -->
        <el-form-item label="项目名称" prop="inspectionName">
          <el-input
            v-model="form.inspectionName"
            placeholder="请输入项目名称"
          />
        </el-form-item>

        <el-form-item label="项目类别" prop="classType">
          <el-input v-model="form.classType" placeholder="请输入项目类别" />
        </el-form-item>
        <el-form-item label="项目单价" prop="unitPrice">
          <el-input v-model="form.unitPrice" placeholder="请输入项目单价" />
        </el-form-item>
        <el-form-item label="项目成本" prop="cost">
          <el-input v-model="form.cost" placeholder="请输入项目成本" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
// import { getList,add,getByid,deleteFile,updateFile } from "@/api/patient/patientfile";
// import {querydp,adddp,deldp,getById,updatedp } from "@/api/dzmorder";
import {
  queryfee,
  deletefee,
  dhipById,
  updatedhip,
  adddhip,
} from "@/api/dzmorder";

export default {
  // doctor  医生
  name: "doctor",
  data() {
    return {
      // 分页后的当前页数据
      list: [],
      //当前数据页的第几页
      currentPage: 1,
      // 总数据条数xx
      total: 0,
      // 每页显示多少行数据,默认为10条
      pagesize: 8,
      // 代表是从后端获取的所有数据
      ticket: [],
      //对话框是否显示
      open: false,
      form: "",
      title: "",
      single: true,
      multiple: true,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      // 显示搜索条件
      showSearch: true,
      tempname: {
        inspectionName: "",
      },
    };
  },
  created() {
    this.getPatientFile();
  },
  methods: {
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {};
      // this.resetForm("form");
    },
    /** 修改按钮操作 */
    // handleUpdate(row) {
    //   this.reset();
    //   const id = row.id || this.ids
    //   getCompare(id).then(response => {
    //     this.form = response.data;
    //     this.open = true;
    //     this.title = "修改招标报价对比";
    //   });
    // },
    /** 查询患者表数据 */
    getPatientFile() {
      //this.listLoading = true;
      queryfee().then((response) => {
        console.log(response.data[0] + "检查项目");
        if (response.code === 200) {
          this.ticket = response.data;
          //获取返回数据的总行数
          this.total = response.data.length;
          // 获取当前页的数据,此方法在下方定义
          this.getDoctorInfo();
          this.$message({
            message: "数据加载成功",
            type: "success",
          });
        } else {
          // 失败提示信息
          this.$$message({
            message: "数据加载错误",
            type: "error",
          });
        }
      });
    },
    // 此方法用来获取当前页的数据
    getDoctorInfo() {
      // 清空表格的list 数据
      this.list = [];
      // 获取当前页的数据
      for (
        let i = (this.currentPage - 1) * this.pagesize;
        i < this.total;
        i++
      ) {
        // 将便利的数据添加到 list 里面
        this.list.push(this.ticket[i]);
        // 判断是否达到每一页的要求
        if (this.list.length === this.pagesize) break;
      }
    },
    // 分页时修改每页的行数,这里会自动传入一个size
    handleSizeChange(size) {
      // 修改当前每页的数据行数
      this.pagesize = size;
      // 数据重新分页
      this.getDoctorInfo();
    },
    // 调整当前的页码
    handleCurrentChange(pageNumber) {
      // 修改当前的页码
      this.currentPage = pageNumber;
      //数据重新分页
      this.getDoctorInfo();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加项目检查";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.open = true;
      const id = row.insId || this.insId;
      console.log("删除id===>>>>>>" + id);

      dhipById(id).then((response) => {
        this.form = response.data;
        // this.open = true;
        this.title = "修改项目检查";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.insId != null) {
            console.log("insid==========>>>" + this.form.insId);
            updatedhip(this.form).then((response) => {
              // this.$modal.msgSuccess("修改成功");
              this.$message({
                message: "数据修改成功",
                type: "success",
              });
              this.open = false;
              this.getPatientFile();
            });
          } else {
            adddhip(this.form).then((response) => {
              this.$message({
                message: "数据添加成功",
                type: "success",
              });

              this.open = false;
              this.getPatientFile();
            });
          }
        }
      });
    },
    // /** 删除按钮操作 */
    // handleDelete(row) {
    //   const ids = row.fileId || this.fileId;
    //   this.$modal.confirm('是否确认删除患者编号为"' + ids + '"的数据项？').then(function() {
    //     return deleteFile(ids);
    //   }).then(() => {
    //     this.getList();
    //     this.$modal.msgSuccess("删除成功");
    //   }).catch(() => {});
    // },
    handleDelete(row) {
      const ids = row.insId || this.insId;
      deletefee(ids).then((response) => {
        this.$message({
          message: "数据删除成功",
          type: "success",
        });
        this.getPatientFile();
      });
    },
    // 模糊查询
    dhipQuery() {
      queryfee(this.tempname).then((response) => {
        console.log(this.tempname)
        if (response.code === 200) {
          this.ticket = response.data;
          //获取返回数据的总行数
          this.total = response.data.length;
          // 获取当前页的数据,此方法在下方定义
          this.getDoctorInfo();
          this.$message({
            message: "数据加载成功",
            type: "success",
          });
        } else {
          // 失败提示信息
          this.$$message({
            message: "数据加载错误",
            type: "error",
          });
        }
      });
    },

    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$modal
        .confirm("是否确认导出所有项目信息？")
        .then(() => {
          this.exportLoading = true;
          return exportPayment(queryParams);
        })
        .then((response) => {
          this.$download.name(response.msg);
          this.exportLoading = false;
        })
        .catch(() => {});
    },
  },
};
</script>

<style lang="scss" scoped>
.app-container {
  width: 100%;
  height: 100%;
}

.app-container .head {
  margin: 0 auto;
  margin-top: 25px;
  width: 95%;
  height: 50px;
  background-color: white;
  box-shadow: 0 0 5px 1px #eeedf2;
}

.app-container .head .el-input {
  //  line-height: 20px;
  margin-top: 10px;
  //  size: 10;
  width: 15%;
}

.app-container .head i {
  margin-right: 10px;
  margin-left: 10px;
  font-style: normal;
}

.app-container .head .select1 {
  margin-top: 10px;
  margin-left: 20px;
}

.app-container .head .add {
  float: right;
  margin-top: 10px;
  margin-right: 10px;
}

.app-container .el-table {
  margin-top: 20px;
}
</style>>



